package com.monlyu.action.deviceuse;

import java.util.Date;
import java.util.List;

import com.monlyu.action.PageAction;
import com.monlyu.bean.Pages;
import com.monlyu.bo.DeviceuseBo;
import com.monlyu.util.DateUtil;
import com.monlyu.util.WebOptUtil;
import com.monlyu.vo.DeviceUse;
import com.monlyu.vo.Devices;
import com.monlyu.vo.User;

/**
 * @author SongJun
 * @since 2010-2-27
 * @description 设备归还
 */
public class EditReturnDeviceAction extends PageAction {

	private DeviceuseBo deviceuseBo;
	private DeviceUse deviceuse;
	private String returnDeviceInfo;
	private Pages<User> users;
	private List<DeviceUse> dus;
	private Long appUserId;
	private Long appDeviceNo;
	private Long retUserId;
	private Long authUserId;

	public Long getAppUserId() {
		return appUserId;
	}

	public void setAppUserId(Long appUserId) {
		this.appUserId = appUserId;
	}

	public Long getAppDeviceNo() {
		return appDeviceNo;
	}

	public void setAppDeviceNo(Long appDeviceNo) {
		this.appDeviceNo = appDeviceNo;
	}

	public Long getRetUserId() {
		return retUserId;
	}

	public void setRetUserId(Long retUserId) {
		this.retUserId = retUserId;
	}

	public Long getAuthUserId() {
		return authUserId;
	}

	public void setAuthUserId(Long authUserId) {
		this.authUserId = authUserId;
	}

	public List<DeviceUse> getDus() {
		return dus;
	}

	public String getReturnDeviceInfo() {
		return returnDeviceInfo;
	}

	public void setReturnDeviceInfo(String returnDeviceInfo) {
		this.returnDeviceInfo = returnDeviceInfo;
	}

	public Pages<User> getUsers() {
		return users;
	}

	public DeviceUse getDeviceuse() {
		return deviceuse;
	}

	public void setDeviceuse(DeviceUse deviceuse) {
		this.deviceuse = deviceuse;
	}

	public void setDeviceuseBo(DeviceuseBo deviceuseBo) {
		this.deviceuseBo = deviceuseBo;
	}

	/**
	 * @author SongJun
	 * @since 2010-2-27
	 * @description 设备归还
	 * */

	public String toReturn() {
		//System.out.println("appUserId = "+appUserId+" appDeviceNo= "+appDeviceNo+" returnDeviceInfo="+returnDeviceInfo);
		int up = deviceuseBo.toReturnDevic(appDeviceNo, returnDeviceInfo, deviceuse,retUserId,authUserId);
		return ajax("成功归还设备共"+up+"个");
	}

	@Override
	public String execute() throws Exception {
		users = deviceuseBo.getUserList(getDefPage());
		return view("editReturnDevice.jsp");
	}

	public String toQuery() {
		
		dus = deviceuseBo.getAppDeviceByUserNo(Devices.DEVICESTATUS_OUT,appUserId, appDeviceNo);
		//System.out.println("返回dus 个数："+dus.size());
		if (dus!=null && dus.size() > 0) {
			deviceuse = dus.get(0);
			appDeviceNo = dus.get(0).getOutapp().getId();
		}
		users = deviceuseBo.getUserList(getDefPage());
		return view("editReturnDevice.jsp");
	}

	/**
	 * 
	 * @author SongJun
	 * @since 2010-3-11
	 * @description
	 * */
	public String toReturnOne() {
		// deviceuse.setReal_enddate(DateUtil.now());
		// deviceuseBo.devicesRet(deviceuse, deviceuse.getId().toString()); //
		// dulists
		// =
		// deviceuseBo.getDeviceuseList(getDefPage());
		// System.out.println(dus.getTotalCount());
		return view("listDeviceuse.jsp");
	}

	
	public String toOff() {
		// deviceuseBo.OffDeviceUse(deviceuse); // dulists =
		// deviceuseBo.getDeviceuseList(getDefPage());
		return view("listDeviceuse.jsp");
	}

}
